// pages/user/register/index.js
const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
const {
  apiBaseUrl
} = require('../../../utils/config.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    userName:'',
    password:'',
    BID:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },
  onColumnChange(e) {
    console.log('picker pick:', e);
  },
  onPickerChange(e) {
    const { key } = e.currentTarget.dataset;
    const { value } = e.detail;
    console.log('picker change:', e.detail);
    this.setData({
      [`${key}Visible`]: false,
      [`${key}Value`]: value,
      [`${key}Text`]: value.join(' '),
    });
  },

  onPickerCancel(e) {
    this.setData({
      cityVisible: false,
    });
  },

  onCityPicker() {
    this.setData({ cityVisible: true });
  },
  inputBID(e){
    this.setData({
      BID:e.detail.value
    })
  },
  inputUserName(e){
    console.log(e)
    this.setData({
      userName:e.detail.value
    })
  },
  inputPassword(e){
    this.setData({
      password:e.detail.value
    })
  },
  inputNo(e){
    this.setData({
      no:e.detail.value
    })
  },
  submit(){
    if(this.data.BID ==''){
      wx.showToast({
        title: '请输入BID！',
        icon:'none'
      })
      return
    }
    else if(this.data.userName ==''){
      wx.showToast({
        title: '请输入姓名！',
        icon:'none'
      })
      return
    }else if(this.data.password =='' || this.data.password.length<6){
      wx.showToast({
        title: '密码长度最低为6位！',
        icon:'none'
      })
      return
    }
    wx.request({
      url: `${apiBaseUrl}Login/user/register/${this.data.userName}/${this.data.password}/${this.data.BID}`,
      success: res => {
        console.log(res);
        if(res.data.code == 200){
          wx.showToast({
            title: '注册成功！',
            icon:'none'
          })
          wx.redirectTo({
            url: '/pages/my/newLogin/newLogin',
          })
        }
        else{
          wx.showToast({
            title: '注册失败',
            icon:'none'
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})